import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const router = new Router({
   routes:[
      {
        path:'/',
        name:'首页',
        redirect:'/login',
        hidden:true,
        component:()=> import('@/components/Login.vue')
      },
      {
        path:'/login',
        name:'login',
        hidden:true,
        component:()=> import('@/components/Login.vue')
      },
      // {
      //    path:'/home',
      //    name:'home',
      //    // () => import('../views/Layout/LayOut.vue')
      //    // component:()=> import('@/components/Home.vue')
      //    component:resolve=>require(['@/components/Home.vue'],resolve)  // 异步组件加载
      // },
      // 学生
      {
         path:'/home',
         name:'学生管理',
         redirect:'/student',
         iconClass:'fa fa-user',
         component:()=> import('@/components/Home.vue'),
         children:[
             {
               path:'/student',
               name:'学生列表',
               iconClass:'fa fa-list',
               component:()=> import('@/components/students/StudentList.vue')
             },
             {
              path:'/student2',
              name:'学生列表2',
              iconClass:'fa fa-list',
              component:()=> import('@/components/students/StudentList2.vue')
             },
             {
              path:'/student3',
              name:'学生列表3',
              iconClass:'fa fa-list',
              component:()=> import('@/components/students/StudentList3.vue')
             },
             {
              path:'/student4',
              name:'学生列表4',
              iconClass:'fa fa-list',
              component:()=> import('@/components/students/StudentList4.vue')
             },
             {
               path:'/info',
               name:'信息列表',
               iconClass:'fa fa-list-alt',
               component:()=> import('@/components/students/InfoList.vue')
             },
             {
               path:'/admin',
               name:'信息管理',
               iconClass:'fa fa-list-alt',
               component:()=> import('@/components/students/InfoAdmin.vue')
             },
             {
               path:'/work',
               name:'作业列表',
               iconClass:'fa fa-list-ul',
               component:()=> import('@/components/students/WorkList.vue')
             },
             {
               path:'/wadmin',
               name:'作业管理',
               iconClass:'fa fa-th-list',
               component:()=> import('@/components/students/WorkAdmin.vue')
             },
         ]
      },
      // 数据
      {
         path:'/home',
         name:'数据分析',
         iconClass:'fa fa-bar-chart',
         component:()=> import('@/components/Home.vue'),
         children:[
             {
               path:'/dataview',
               name:'数据概览',
               iconClass:'fa fa-line-chart',
               component:()=> import('@/components/dataAnyals/DataView.vue')
             },
             {
               path:'/mapview',
               name:'地图概览',
               iconClass:'fa fa-line-chart',
               component:()=> import('@/components/dataAnyals/MapView.vue')
             },
             {
               path:'/travel',
               name:'旅游地图',
               iconClass:'fa fa-line-chart',
               component:()=> import('@/components/dataAnyals/TravelMap.vue')
             },
             {
               path:'/score',
               name:'分数地图',
               iconClass:'fa fa-line-chart',
               component:()=> import('@/components/dataAnyals/ScoreMap.vue')
             },
         ]
      },
      {
         path:'/home',
         name:'用户中心',
         iconClass:'fa fa-user',
         component:()=> import('@/components/Home.vue'),
         children:[
            {
              path:'/user',
              name:'权限管理',
              iconClass:'fa fa-user',
              component:()=> import('@/components/users/User.vue')
            },
            {
              path:'/usertree',
              name:'树形菜单操作',
              iconClass:'fa fa-user',
              component:()=> import('@/components/users/UserTree.vue')
            },
            {
              path:'/tableadddelete',
              name:'表格的新增删除',
              iconClass:'fa fa-user',
              component:()=> import('@/components/users/TableAddDelete.vue')
            },
            {
              path:'/tableexcel',
              name:'导出表格数据',
              iconClass:'fa fa-user',
              component:()=> import('@/components/users/TableExcel.vue')
            },
            {
              path:'/tableexcel2',
              name:'导出表格数据2',
              iconClass:'fa fa-user',
              component:()=> import('@/components/users/TableExcel2.vue')
            },
            
         ]
       },
      {
         path:'*',
         name:'notfound',
         hidden:true,
         component:()=> import('@/components/NotFound.vue')
      },
   ],
   mode:'history'   // hash
})


router.onError((error) => {
  const jsPattern = /Loading chunk (\d)+ failed/g;
  const cssPattern = /Loading CSS chunk (\S)+ failed/g;
  console.log('223333333');
  const isChunkLoadFailed = error.message.match(jsPattern||cssPattern);
  const targetPath = router.history.pending.fullPath;
  if (isChunkLoadFailed) {
    //router.replace(targetPath);
    window.location.reload();
  }
});



// 路由守卫  也可以写在这里
// router.beforeEach((to,from,next)=>{})



export default router;